//1.导入koa-router包
const Router = require('koa-router')
const {auth} = require('../middleware/auth.middleware')
const {Validator} = require('../middleware/addr.middleware')
const {create,getAddress,update,remove,updateDefault} = require('../controller/addr.controller')
//2.实例化对象
const router = new Router({prefix:'/address'})
//3.编写路由规则
router.post('/',auth,Validator({
    consignee:'string',
    phone:{type:'string',format:/^1\d{10}$/},
    address:'string'
}),create)
router.get('/',auth,getAddress)
router.put('/:id',auth,Validator({
    consignee:'string',
    phone:{type:'string',format:/^1\d{10}$/},
    address:'string'
}),update)
router.delete('/:id',auth,remove)
router.patch('/:id',auth,updateDefault)
//3.导出router对象
module.exports = router